package com.zyy.game.tianlong.task;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author relufi
 * @date 2019/8/14 0014
 */
@Component
public class GameInitRun implements ApplicationRunner {
    private final StringRedisTemplate redisTemplate;
    /**
     * 签到奖励key
     */
    public static final String SIGN_IN_REWARD = "Setting::SignInReward";

    public GameInitRun(StringRedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    @Override
    public void run(ApplicationArguments args) {
        ListOperations<String, String> opsForList = redisTemplate.opsForList();
        Long size = opsForList.size(SIGN_IN_REWARD);
        if(size == null || size != 7) {
            redisTemplate.delete(SIGN_IN_REWARD);
            opsForList.rightPushAll(SIGN_IN_REWARD,"100","200","300","400","500","600","700");
        }
    }
}
